<%@ page import="java.util.ArrayList" %>
<%@ page import="com.zhiyou.entity.User" %>
<%@ page import="com.zhiyou.util.DBUtil" %>
<%@ page import="com.zhiyou.entity.Column" %>
<%@ page import="com.zhiyou.entity.PowerCenter" %>
<%--
  Created by IntelliJ IDEA.
  User: 磊布斯
  Date: 2021/9/1
  Time: 15:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <link href="../css/main.css" rel="stylesheet">
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='addusername']").blur(function(){
                var name=$("input[name='addusername']").val();
                $.ajax({
                    type: "GET",
                    url: "../DoAddServlet",
                    data: {username:name},
                    dataType: "json",
                    success:function(data){//成功的时候要执行的函数
                        //alert(data.msg);//json对象  response:success
                        //根据key 得到 value
                        var eValue=eval('data.'+'response');
                        if(eValue!="success"){
                            //做自己想做的事情
                            $("#div111").text("此用户名不可添加");
                            $("input[name='addusername']").val("");
                        }
                    },
                    error:function(d,errorThrown){//失败的时候要执行的函数
                        alert("失败");
                        alert(d.status);
                        alert(d.readyState);
                        alert(errorThrown);
                    }

                });

            });
        });
        $(function () {
            $("input[name='addusername']").focus(function () {
                $("#div111").text("")
            })
        })
    </script>
</head>
<body>
<%
    ArrayList<PowerCenter> pcList = (ArrayList<PowerCenter>) session.getAttribute("pcList");
    String add = (String) session.getAttribute("add");
    String alter = (String) session.getAttribute("alter");
    String delete = (String) session.getAttribute("delete");
    String addPower = (String) session.getAttribute("addPower");
    if ("success".equals(add)){
        %>
<script type="text/javascript">
    alert("新增成功")
</script>
<%
    }
    session.removeAttribute("add");
    if ("success".equals(alter)){
        %>
<script type="text/javascript">
    alert("更新成功")
</script>
<%
    }
    session.removeAttribute("alter");
    if ("success".equals(delete)){
        %>
<script type="text/javascript">
    alert("删除成功")
</script>
<%
    }
    session.removeAttribute("delete");
    if ("success".equals(addPower)){
        %>
<script type="text/javascript">
    alert("授权成功")
</script>
<%
    }
    session.removeAttribute("addPower");
%>
<div class="AccountManagement_c " id="AccountManagement_c">
    <h3>账户管理
        <form action="../DoSearchServlet" method="post">
        <div class="amcl fr">
            <input type="text" placeholder="用户名" class="fl" name="searchName">
            <button class="search fl" type="submit"><img src="../images/search.png"></button>
        </div>
        </form>
    </h3>
    <div class="AM_ct text_center">
        <div class="AM_ct_in">
            <div class="add_btn df_btn fl" id="add_Account_btn">添加</div>
            <div class="edit_btn df_btn fl" id="edit_Account_btn">编辑</div>
            <div class="delete_btn df_btn fl" id="delete_Account_btn">删除</div>
            <div class="fr df_btn ac_btn" id="ac_Account_btn">账号授权</div>
        </div>
    </div>

    <div class="list">
        <ul class="list_h">
            <li class="b20"><label><input type="checkbox" name=""><span>用户名</span></label></li>
            <li class="b20"><label>密码</label></li>
            <li class="b60"><label>授权形式</label></li>
        </ul>
        <div class="list_b_c">
            <%
                if(pcList.size() > 0){
                for (int i = 0; i < pcList.size(); i++) {
            %>
                <ul class="list_b">
                    <li class="b20"><label><input type="checkbox" name=""><span><%=pcList.get(i).getAcct()%></span></label></li>
                    <li class="b20"><label><%=pcList.get(i).getUser().getPassWord()%></label></li>
                    <%
                        if (pcList.get(i).getChnlCode()==null){
                            %>
                    <li class="b60"><label>暂无授权</label></li>
                    <%
                        }else{
                            %>
                    <li class="b60"><label><%=pcList.get(i).getColumn().getName()%></label></li>
                    <%
                        }
                    %>
                </ul>
            <%
                }
            %>

        </div>
        <div class="pull_page">
            <div class="fl pull_page_up"><a href="../DoGetPageUsers.jsp?pageIndex=${pageIndex-1}">上一页</a></div>
            <ul>
                <li class="on"><a href="../DoGetPageUsers.jsp?pageIndex=1">1</a></li>
                <li><a href="../DoGetPageUsers.jsp?pageIndex=2">2</a></li>
                <li><a href="../DoGetPageUsers.jsp?pageIndex=3">3</a></li>
                <li class="pull_page_df_btn">…</li>
                <li><a href="../DoGetPageUsers.jsp?pageIndex=${pages}">末页</a></li>
            </ul>
            <div class="fl pull_page_down"><a href="../DoGetPageUsers.jsp?pageIndex=${pageIndex+1}">下一页</a></div>
        </div>
        <%
            }
                else{
                    %>
        <ul class="list_null">
        <li class="text_center">未查到相关数据！</li>
        </ul>
        <%
            }
        %>
    </div>
</div>
<!-- 弹窗 -->
<!-- 添加账户 -->
<form action="../DoAddServlet" method="post">
        <div class="add_Account dn" id="add_Account">
            <div class="add_Account_c">
                <div class="add_Account_h">
                    <div class="add_Account_h_in">
                        添加账户
                        <span class="fr add_Account_close"><img src="../images/close.png"></span>
                    </div>
                </div>
                <div class="user_name user_i">
                    <label>用户名</label> <input type="text" placeholder="输入用户名" name="addusername">
                </div>
                <div class="user_password user_i">
                    <label>密<i>调</i>码</label> <input type="password" placeholder="输入密码" name="addpassword">
                </div>
                <div id="div111"></div>
                <button class="add_Account_ok_btn text_center" id="add_Account_ok_btn" type="submit" >确<i>皮</i>定</button>
            </div>
        </div>
</form>
<!-- 账户编辑 -->
<form action="../DoAlterServlet" method="post">
    <div class="add_Account dn" id="user_column">
        <div class="add_Account_c">
            <div class="add_Account_h">
                <div class="add_Account_h_in">
                    编辑账户
                    <span class="fr add_Account_close"><img src="../images/close.png"></span>
                </div>
            </div>
            <div class="column_now ">正在编辑 “<span id="alterAcct"></span>”账户</div>
            <div class="user_name user_i">
                <label>用户名</label> <input type="text" placeholder="输入用户名" name="username" readonly="readonly">
            </div>
            <div class="user_password user_i">
                <label>密<i>调</i>码</label> <input type="password" placeholder="输入密码" name="password">
            </div>
            <button class="add_Account_ok_btn text_center" id="user_column_ok_btn" type="submit">确<i>皮</i>定</button>
        </div>
    </div>
</form>
<!-- 删除账户 -->
<form action="../DoDeleteServlet" method="post">
    <div class="add_Account dn" id="delete_Account">
        <div class="add_Account_c">
            <div class="add_Account_h">
                <div class="add_Account_h_in">
                    删除账户
                    <span class="fr add_Account_close"><img src="../images/close.png"></span>
                </div>
            </div>
            <div class="delete_text">确定删除“ <span id="deleteAcct"></span> ”账户吗？</div>
            <input type="text" style="display:none" name="deleteAcct2"/>
            <button type="submit" class="add_Account_ok_btn text_center" id="delete_Account_ok_btn">确<i>皮</i>定</button>
        </div>
    </div>
</form>

<!-- 账户授权 -->
<div class="add_Account dn" id="ac_Account">
    <form action="../DoChooice" method="post">
        <div class="add_Account_c" id="addPower">
            <div class="add_Account_h">
                <div class="add_Account_h_in">
                    账户栏目授权
                    <span class="fr add_Account_close"><img src="../images/close.png"></span>
                </div>
            </div>
            <ul>
                    <c:forEach var="column" items="${columnList}">
                    <li><label><input type="checkbox" name="">&nbsp;<span>${column.name}</span></label>
                    </c:forEach>
            </ul>
            <%--选中的用户--%>
            <input type="text" style="display: none" name="addPowerAccountName" />
            <%--选中的授权处--%>
            <input type="text" style="display: none" name="addPowerName" />
            <button class="add_Account_ok_btn text_center" id="ac_Account_ok_btn">保<i>呀</i>存</button>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</html>
